package kr.ac.hufs.ice.cap.network;


import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import kr.ac.hufs.ice.cap.network.NetworkData;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

public class NetworkThread_Visit extends Thread {
	  
    NetworkData nd;
    Handler mHandler;
    int commandState; 
    private final String SERVER_ADDRESS = "http://220.67.124.69/requestinfo/visit_request.php"; 
    
    public static final int REGISTER = 0;
    
    public NetworkThread_Visit(NetworkData nd, Handler mHandler) {
            this.nd = nd;
            this.mHandler = mHandler;
    }
    
    public void setCommand(int command) {
            this.commandState = command;
    }
    
    public void run() {
            Looper.prepare();
            if(commandState == REGISTER) {
                    register();     
            }
            
            Looper.loop();
    }
    
    private void register() {
            
//          String ID = nd.getId();
//          String PassWord = nw.getPassWord();
            String ParentName = nd.getParentName();
            String ParentPhoneNumber = nd.getParentPhoneNumber();
            String VisitPurpose = nd.getVisitPurpose();
            String VisitDate = nd.getVisitDate();
            
            PageStreamer ps = new PageStreamer();
            ps.setRootURL(SERVER_ADDRESS);
//          ps.add("Id", ID);
//          ps.add("PassWord", PassWord);
            ps.add("ParentName", ParentName);
            ps.add("ParentPhoneNumber", ParentPhoneNumber);
            ps.add("VisitPurpose", VisitPurpose);
            ps.add("VisitDate", VisitDate);
            
            String returnMsg = ps.getPageStream();
            Message msg = new Message();
            if(returnMsg.contains("1")) {
                    msg.obj = returnMsg;
            }
            mHandler.sendMessage(msg);
    }
}